/*
 * LevelGenerator.cpp
 *
 *  Created on: Dec 1, 2010
 *      Author: timmeh
 */
#define res SDLResource::Instance()

#include "SDLLevelGenerator.h"
#include <iostream>
#include <vector>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "SDLLevel.h"
#include "SDLResource.h"
#include "SDLPowerUp.h"

using namespace std;
using bo::Level;

bo_sdl::SDLLevelGenerator::SDLLevelGenerator(AbstractFactory* fact):
		LevelGenerator(fact){
}

bo_sdl::SDLLevelGenerator::~SDLLevelGenerator(){

}

/**
 * Sets the factory to be used
 */
void bo_sdl::SDLLevelGenerator::SetFact(AbstractFactory* fact){
	LevelGenerator::SetFact(fact);
}

/**
 * Creates a standard level. Objects are created according to the screen size, so the entire screen is filled at all times
 */
bo_sdl::SDLLevel* bo_sdl::SDLLevelGenerator::CreateStandardLevel(const char* ballFileName, const char* paddleFileName, const char* breakFileName){
	SDLLevel* lvl = new SDLLevel;
	lvl->AddBall(this->GetFact()->CreateBall(ballFileName, 0, -1.8, .05, .05, res->GetScale()));
	SDL_Surface* tempBreak = IMG_Load(breakFileName);
	double dist = tempBreak->w/res->GetScale();
	double amInRow = 7.5 / dist;
	lvl->AddPaddle(this->GetFact()->CreatePaddle(paddleFileName, 0, -2.8, res->GetScale(), 0.04));
	for (double i = -4 + dist; i < 3.75; i+=(7.5 / amInRow)){
		for (double j = 2.8; j > 0; j-=(1*dist)){
			lvl->AddToLevel(this->GetFact()->CreateBreakable(breakFileName, i, j, res->GetScale()));
		}
	}
	return lvl;
}

